Page({

  /**
   * 页面的初始数据
   */
  data: {
    timeList:[],
    isActive: 1,
    beginDay:"",
    endDay:"",
    count:"",
    city: "南京",
    nowDate: "",
    show: false,
    imgList: [
      "https://webimgs.bthhotels.com/image/f3edc780-7ab3-4a43-877b-995692a3e071.png",
      "https://webimgs.bthhotels.com/image/f3edc780-7ab3-4a43-877b-995692a3e071.png",
      "https://webimgs.bthhotels.com/image/f3edc780-7ab3-4a43-877b-995692a3e071.png",
      "https://webimgs.bthhotels.com/image/f3edc780-7ab3-4a43-877b-995692a3e071.png",
    ],
    img_info:"https://images.bthhotels.com/web/Image/20200420/44bcd6b7-a6b8-47a3-a891-184f9dde9f3f.jpg"
  },
  getCity(even) {
    console.log(even);
    wx.setStorageSync('selectCity', even.detail.code[2])
    let i = even.detail.value.length
    let city = even.detail.value[i - 1]
    this.setData({
      city: city
    })
  },

  onClose() {
    this.setData({
      show: false,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const myDate = new Date();
    // 当前时间
    const month = myDate.getMonth() + 1
    const day = myDate.getDate()
    const nowDay = month + "/" + day
    console.log(nowDay);
    this.setData({
      beginTime : nowDay
    })



  },
  goHotel(e){
    console.log(e);
    let hotelTime = e.currentTarget.dataset.timelist
    hotelTime[2].city = e.currentTarget.dataset.addr
    console.log(hotelTime);
    wx.setStorageSync('hotleTime', hotelTime)
    wx.navigateTo({
      url: '/pages/hotel/index',
    
    })
    
  },

  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  onConfirm(even) {
    let {startTimeStr,endTimeStr} = this.getStringTime(even.detail[0],even.detail[1])
    console.log(startTimeStr);
    console.log(endTimeStr);
    const beginMonth = even.detail[0].getMonth() + 1
    const beginDay = even.detail[0].getDate() 
    const endMonth = even.detail[1].getMonth() + 1
    const endDay = even.detail[1].getDate() 
    const begin = beginMonth + "/" + beginDay
    const end = endMonth + "/" + endDay
    const timeDiff = Math.abs( even.detail[1].getTime() -  even.detail[0].getTime());
    const count ="共" +  Math.ceil(timeDiff / (1000 * 60 * 60 * 24)) + "晚";
    const timeList = [
      {beginTime:startTimeStr,info:begin},
      {endTime:endTimeStr,info:end},
      {city:""}
    ]
    this.setData({
      show: false,
      timeList : timeList,
      count : count
    });
  },
  geTime(){

  },

  selectActive(even) {
    let id = even.target.dataset.id
    this.setData({
      isActive: id
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 传入开始时间，结束时间，返回开始当天12点的时间戳，结束当天的时间戳
   */
  getStringTime(startTime,endTime){
    startTime.setHours(12)
    startTime.setMinutes(0)
    startTime.setSeconds(0)
    const startTimeStr = startTime.getTime() / 1000
    console.log(startTimeStr);
    endTime.setHours(12)
    endTime.setMinutes(0)
    endTime.setSeconds(0)
    const endTimeStr = endTime.getTime() /1000
    const time = {
      startTimeStr: startTimeStr,
      endTimeStr: endTimeStr
    }
    return time;
  }
})